package com.example.zjx8969.myapplication.banner;

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

import java.util.Calendar;
import java.util.List;

@Dao
public abstract class BannerDao {
    @Query("select * from home_banner where   :currentTime<endTime")
    protected abstract List<BannerBean> getAll(long currentTime);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    public abstract void insert(List<BannerBean> beans);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    public abstract void insert(BannerBean bean);

    public List<BannerBean> getAll() {
        return getAll(Calendar.getInstance().getTimeInMillis() / 1000);
    }

    @Query("delete from home_banner where :current>endTime")
    protected abstract void delete(long current);

    public void deleteOutOfTimeRecord() {
        delete(Calendar.getInstance().getTimeInMillis() / 1000);
    }

    @Query("delete from home_banner")
    public abstract void deleteAll();
}
